<template>
  <div class="my-pagination" v-if="total>0">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[10, 20, 50, 100]"
      background
      :page-size="limit"
      next-text=">"
      prev-text="<"
      layout="total, prev, pager, next,slot "
      :total="total"
      :current-page="currentPage"
    >
      <span class="gong111"
        >共{{ totalPage }}页，到第<input
          class="inpuiu111"
          v-model="currentPage"
        />页
        <!-- <div @click="handleClick">确定</div> -->
      </span>
    </el-pagination>
  </div>
</template>

<script>
export default {
  props: {
    limit: {
      type: Number,
      default: 10
    },
    // 总条数
    total: {
      type: Number,
      default: 19
    },
    page: {
      type: Number,
      default: 1
    }
  },
  computed: {
    // 总页数
    totalPage () {
      const res1 = this.total / this.limit
      const res2 = parseInt(res1)
      if (res1 - res2 > 0) {
        return res2 + 1
      } else {
        return res2
      }
    }
  },
  data () {
    return {
      currentPage: 1
    }
  },
  watch: {
    page: {
      handler (newVal, oldVal) {
        this.currentPage = newVal
      },
      immediate: true
    }
  },

  mounted () {},

  methods: {
    handleSizeChange (val) {
      this.limit = val
      this.confirmData()
    },
    handleCurrentChange (val) {
      this.currentPage = val
      this.confirmData()
    },
    handleClick () {
      this.confirmData()
    },

    confirmData () {
      const obj = {
        limit: Number(this.limit),
        total: Number(this.total),
        totalPage: Number(this.totalPage),
        currentPage: Number(this.currentPage)
      }
      this.$emit('change', obj)
    }
  }
}
</script>

<style lang="scss" scoped>
.my-pagination {
  display: flex;
  justify-content: center;
  margin-top: 10px;
  font-size: 12px;
  /deep/ .el-pagination__editor.el-input .el-input__inner {
    height: 28px !important;
  }
  /deep/ .el-input--mini .el-input__inner {
    height: 28px !important;
  }
}

.my-pagination .el-pagination.is-background .el-pager li {
  width: 28px;
  height: 28px;
  background-color: #ffffff;
  font-weight: 400;
  border: 1px solid #d9d9d9;
}

.my-pagination .btn-next,
.my-pagination .btn-prev {
  background: #f2f2f2 !important;
  width: 68px;
  color: #000000;
  border: 1px solid #d9d9d9 !important;
  height: 28px !important;
}

/deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
  width: 28px;
  font-weight: 400;
  height: 28px;
  background: #e22a1f;
  border-radius: 4px;
}
/deep/ .el-pagination.is-background .el-pager li:not(.disabled):hover {
  color: #e22a1f;
}
/deep/ .el-pagination.is-background .el-pager li:not(.disabled).active:hover {
  color: #fff;
}
/deep/ .number {
  border-radius: 4px !important;
  border: 1px solid #e8e8e8;
  border-left: 1px solid #e8e8e8 !important;
}
.inpuiu111 {
  width: 28px;
  height: 22px;
  background: #ffffff;
  border: 1px solid #d9d9d9;
  outline: none;
  text-align: center;
  margin-left: 10px;
  margin-right: 12px;
}
.gong111 {
  width: 86px;
  height: 20px;
  font-size: 14px;
  font-family: Source Han Sans SC, Source Han Sans SC-Regular;
  font-weight: 400;
  text-align: left;
  color: #999;
}
.gong111 div {
  height: 26px;
  padding: 0 5px;
  background: #fff;
  border: 1px solid #e22a1f;
  line-height: 26px;
  display: inline-block;
  font-size: 14px;
  font-family: Source Han Sans SC, Source Han Sans SC-Regular;
  font-weight: 500;
  text-align: center;
  color: #e22a1f;
  margin-left: 16px;
  cursor: pointer;
  border-radius: 4px;
}

/deep/.btn-next {
  margin-right: 16px !important;
}
/deep/.btn-prev span {
  color: #000000;
  font-weight: 500 !important;
}
/deep/.btn-next span {
  color: #000000;
  font-weight: 500 !important;
}
/deep/ .el-pagination.is-background .btn-next {
  background-color: #fff;
  border-radius: 4px;
  border: 1px solid #e8e8e8;
}
/deep/ .el-pagination.is-background .btn-prev {
  background-color: #fff;
  border-radius: 4px;
  border: 1px solid #e8e8e8;
}
/deep/ .el-pagination__total {
  color: #999999;
}

</style>
